#!/usr/bin/perl


use strict;
use warnings;

our %Commands;
my %PosibleCommands;


$Commands{'show library'} = sub {
	print "show library\n";
    return 0;
};


$Commands{'show libvolumes'} = sub {
	print "show libvolumes\n";
    return 0;
};

$Commands{'help'} = sub {
	print "help\n";
    return 0;
};


$Commands{'show faszom'} = sub {
	print "show faszom\n";
    return 0;
};



foreach (keys %Commands) {
	my $oc = $_; ## OriginalCommand
	$, = /\s/;
	my @cws = (split); ## CommandWords
	while (length($cws[0]) > 1) {
		if (defined ($cws[1]) ) {
			my $t_cw = $cws[1];
			while  (length($t_cw) > 1) {
				print $cws[0]." ".$t_cw. "=> $oc"."\n";
				if (defined $PosibleCommands {$cws[0]." ".$t_cw}) {
					delete $PosibleCommands {$cws[0]." ".$t_cw};
				} else {
					$PosibleCommands {$cws[0]." ".$t_cw} = $oc;
				}
				$t_cw = substr($t_cw, 0,(length($t_cw)-1));
			}
		} else {
		print $cws[0]."=> $oc"."\n";
			if (defined $PosibleCommands {$cws[0]}) {
					delete $PosibleCommands {$cws[0]};
				} else {
					$PosibleCommands {$cws[0]} = $oc;
			}
		}
	$cws[0] = substr($cws[0], 0,(length($cws[0])-1));
	}
}





print "#############################\n";
foreach (keys %PosibleCommands ) {
	print "CMD: $_  -> $PosibleCommands{$_}\n";
	&{ $Commands{$PosibleCommands{$_}}};
}
